package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.model.common.constants.HotArticleConstants;
import com.heima.model.common.mess.ArticleVisitStreamMess;
import com.heima.model.common.mess.UpdateArticleMess;
import org.apache.commons.lang.StringUtils;
import org.apache.kafka.streams.StreamsBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class ArticleIncrHandleListener {
    @Autowired
    private ApArticleService apArticleService;
    @KafkaListener(topics = HotArticleConstants.HOT_ARTICLE_INCR_HANDLE_TOPIC)
    public void onMessage(String message) {
        if(StringUtils.isNotBlank(message)){
            System.out.println(message);
            ArticleVisitStreamMess mess = JSON.parseObject(message, ArticleVisitStreamMess.class);
            apArticleService.updateArticleScore(mess);
        }
    }
}
